<template>
  <page-header-wrapper>
    <a-card :bordered="false">
      <div class="table-operator">
        <a-button type="primary" icon="plus" @click="handleAdd">添加</a-button>
      </div>
      <!-- table栏区域 -->
      <s-table
        ref="table"
        bordered
        size="default"
        rowKey="key"
        :columns="columns"
        :data="loadData"
        :loading="loading"
        showPagination="auto"
      >
        <span slot="action" slot-scope="text, record">
          <template>
            <!--          <a-divider type="vertical" />-->
            <a @click="handleEdit(record)">编辑</a>
            <a-divider type="vertical" />
            <a-popconfirm  title="确定删除吗?" @confirm="() => handleSub1(record.id)">
              <a style="color: #ED3F14">删除</a>
            </a-popconfirm>
            <!--          <--<a-popconfirm v-if="forbidden == true" title="确定停用吗?" @confirm="() => handleSub1(record.id)">-->
            <!--            <a style="color: #ED3F14">停用</a>-->
            <!--          </a-popconfirm>-->
            <!--          <a-popconfirm v-if="forbidden == false" title="确定恢复吗?" @confirm="() => handleSub2(record.id)">-->
            <!--            <a style="color: #56CC66">恢复</a>-->
            <!--          </a-popconfirm>-->
          </template>
        </span>
      </s-table>
      <!--   modal  -->
      <a-modal v-model="visible_qx" title="商业权限管理" @ok="handleOk_qx">
        <p>商家名称 R-one美妆官方商城 </p>
        <a-checkbox-group @change="onChange_q">
          <a-row>
            <a-col :span="4">
              <span>权限管理</span>
            </a-col>
            <a-col :span="20" >
              <a-checkbox value="A">
                显示水印权限，没有该权限的不显示客户自己的水印
              </a-checkbox>
            </a-col>
            <a-col :span="20" :offset="4">
              <a-checkbox value="B" >
                化妆教程权限，没有改权限的不显示化妆教程
              </a-checkbox>
            </a-col>
            <a-col :span="20" :offset="4">
              <a-checkbox value="C">
                肤质检测权限-图像测肤，没有权限的不显示测肤按钮
              </a-checkbox>
            </a-col>
            <a-col :span="20" :offset="4">
              <a-checkbox value="D">
                肤质检测权限-接触测肤，没有权限的不显示测肤按钮
              </a-checkbox>
            </a-col>
          </a-row>
        </a-checkbox-group>
      </a-modal>
    </a-card>
  </page-header-wrapper>
</template>

<script>
import moment from 'moment'
import { STable, Ellipsis } from '@/components'
import { getRoleList, getServiceList } from '@/api/manage'

const columns = [
  // {
  //   title: '#',
  //   scopedSlots: { customRender: 'serial' }
  // },
  {
    title: '美妆教程的简体名称',
    dataIndex: 'no',
    align: 'center'
  },
  {
    title: '美妆教程的简体图片',
    dataIndex: 'description',
    align: 'center',
    scopedSlots: { customRender: 'description' }
  },
  {
    title: '关键字',
    dataIndex: 'no',
    align: 'center'
  },
  {
    title: '备注',
    dataIndex: 'description',
    align: 'center',
    scopedSlots: { customRender: 'description' }
  },
  {
    title: '创建时间',
    dataIndex: 'callNo',
    align: 'center',
    // sorter: true,
    // needTotal: true,
    customRender: (text) => text + ' 次'
  },
  {
    title: '操作',
    dataIndex: 'action',
    align: 'center',
    width: '20%',
    scopedSlots: { customRender: 'action' }
  }
]
export default {
  name: 'AddBrand',
  components: {
    STable,
    Ellipsis
  },
  data () {
    this.columns = columns
    return {
      // create model
      visible: false,
      visible_qx: false,
      confirmLoading: false,
      forbidden: false,
      mdl: null,
      // 高级搜索 展开/关闭
      advanced: false,
      // 查询参数
      queryParam: {},
      // 加载数据方法 必须为 Promise 对象
      loadData: parameter => {
        const requestParameters = Object.assign({}, parameter, this.queryParam)
        console.log('loadData request parameters:', requestParameters)
        return getServiceList(requestParameters)
          .then(res => {
            return res.result
          })
      },
      selectedRowKeys: [],
      selectedRows: []
    }
  },
  created () {
    getRoleList({ t: new Date() })
  },
  computed: {
    rowSelection () {
      return {
        selectedRowKeys: this.selectedRowKeys,
        onChange: this.onSelectChange
      }
    }
  },
  methods: {
    // 添加 的方法
    handleAdd () {
      this.visible_qx = true
    },
    // 编辑 的方法
    handleEdit (record) {
      this.visible_qx = true
      this.visible = false
      this.mdl = { ...record }
    },
    // 添加、编辑 点击确定的方法
    handleOk () {
      const form = this.$refs.createModal.form
      this.confirmLoading = true
      form.validateFields((errors, values) => {
        if (!errors) {
          console.log('values', values)
          if (values.id > 0) {
            // 修改 e.g.
            new Promise((resolve, reject) => {
              setTimeout(() => {
                resolve()
              }, 1000)
            }).then(res => {
              this.visible = false
              this.confirmLoading = false
              // 重置表单数据
              form.resetFields()
              // 刷新表格
              this.$refs.table.refresh()

              this.$message.info('修改成功')
            })
          } else {
            // 新增
            new Promise((resolve, reject) => {
              setTimeout(() => {
                resolve()
              }, 1000)
            }).then(res => {
              this.visible = false
              this.confirmLoading = false
              // 重置表单数据
              form.resetFields()
              // 刷新表格
              this.$refs.table.refresh()

              this.$message.info('新增成功')
            })
          }
        } else {
          this.confirmLoading = false
        }
      })
    },
    handleCancel () {
      this.visible = false
      this.visible_qx = false

      const form = this.$refs.createModal.form
      form.resetFields() // 清理表单数据（可不做）
    },
    onChange_q (checkedValues) {
      console.log('checked = ', checkedValues)
    },
    handleOk_qx () {
    },
    // 是否禁用、启用
    handleSub1 () {
      this.forbidden = false
    },
    handleSub2 () {
      this.forbidden = true
    },
    handleSub (record) {
      // if (record.status !== 0) {
      //   this.$message.info(`${record.no} 订阅成功`)
      // } else {
      //   this.$message.error(`${record.no} 订阅失败，规则已关闭`)
      // }
    },
    onSelectChange (selectedRowKeys, selectedRows) {
      this.selectedRowKeys = selectedRowKeys
      this.selectedRows = selectedRows
    },
    resetSearchForm () {
      this.queryParam = {
        date: moment(new Date())
      }
    }
  }
}
</script>

<style scoped>

</style>
